import collection from 'collection';
import ProductSku from './product-sku';

export default class Sku extends collection.Entity{
    constructor(){
        super();
        this.id = 0;
        this.total = 0; // 库存总量
        this.productId = 0; // 产品Id
        this.link=null;
        this.price = 0;
        this.remark = null;
        this.skuPropertyItems = []; // 

        this.skuItems = [];
        this.checked = false;
    }

    generate_link(){
       var propertyItemIdList =  _.map(this.skuPropertyItems, function(item){ return item.propertyItemId});
       this.link = _.sortBy(propertyItemIdList).join('-');
    }

    to_product_sku(){
        var productSku = new ProductSku();        
        productSku.price = this.price;
        productSku.remark = this.remark;
        productSku.propertyItems = this.skuPropertyItems;
        productSku.skuId = this.id;
        return productSku;
    }
}